<%--
  Created by IntelliJ IDEA.
  User: 老头
  Date: 2023/4/13
  Time: 21:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@page import="java.sql.*"%>
    <%@page import="util.*"%>
    <%
        request.setCharacterEncoding("UTF-8");
        String name = request.getParameter("myName");
        String password = request.getParameter("myPassword");

        Connection connection = JDBCUtil.getConnection();
        String sql = "SELECT * FROM user WHERE username = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, name);
        ResultSet rs = preparedStatement.executeQuery();
        rs.next();
        System.out.println(password);
        System.out.println(rs.getString(3));
        if (password.equals(rs.getString(3))) {
            //  out.println("登录成功");
            request.getSession().setAttribute("username", name);
            response.sendRedirect(request.getContextPath() + "/client/loginsuccess.jsp");
        }else {
            //账号密码错误
            session.setAttribute("Message", "账号密码错误");
            response.sendRedirect(request.getContextPath() + "/client/loginfail.jsp");
        }

    %>
</head>
<body>

</body>
</html>
